<?php

namespace core\lib;

class route
{
    public $ctrl;
    public $action;

    /*
     * XXX.COM/index.php/index/index
     * 1 隐藏index.php
     * 2 获取URL参数部分
     * 3 返回对应的控制器和方法
     * 4 返回URL中GET传值信息
     * */
    public function __construct()
    {
        if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/') {
            $path = $_SERVER['REQUEST_URI'];
            $path = explode('/', trim($path, '/'));
            if (isset($path[0])) {
                $this->ctrl = ucfirst($path[0]);
                unset($path[0]);
            }
            if (isset($path[1])) {
                $this->action = $path[1];
                unset($path[1]);
            } else {
                $this->action = conf::get('ACTION', 'route');
            }
            $path = array_values($path);
            $i = 0;
            while ($i < count($path)) {
                if (isset($path[$i + 1])) {
                    $_GET[$path[$i]] = $path[$i + 1];
                }
                $i = $i + 2;
            }
        } else {
            $this->ctrl = ucfirst(conf::get('CTRL', 'route'));
            $this->action = conf::get('ACTION', 'route');
        }
    }
}